#!/usr/bin/env python3
# encoding: utf-8


import time
import sys
import os
import os.path
import logging
import argparse
from typing import List


import requests


def parse_args():
    parser = argparse.ArgumentParser(description='Uplooooooooad')
    parser.add_argument('-d', '--dir',
                        required=True)
    return parser.parse_args()


def upload(dir):
    errors = []
    for item in os.listdir(dir):
        if os.path.isdir(item):
            continue
        filename = os.path.join(dir, item)
        f = open(filename, 'rb')
        data = f.read()
        f.close()
        req = requests.put("http://127.0.0.1:7000/api/_fs/" + item, data=data)
        if not req.ok:
            errors.append(filename)
            print("error: " + filename)
        print(req.content)
        time.sleep(3)
    print(errors)

if __name__ == '__main__':
    args = parse_args()
    upload(args.dir)
